package com.ycfmedical.bed.adapter;

import com.bilibili.magicasakura.widgets.TintImageView;
import com.bilibili.magicasakura.widgets.TintTextView;
import com.ycfmedical.bed.R;
import com.ycfmedical.bed.model.HealthResults;
import com.zhy.autolayout.utils.AutoUtils;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import butterknife.BindView;
import cn.droidlover.xdroidmvp.base.SimpleRecAdapter;
import cn.droidlover.xdroidmvp.imageloader.ILFactory;
import cn.droidlover.xdroidmvp.kit.KnifeKit;

/**
 * Created by wanglei on 2016/12/10.
 */

public class HealthRegimenAdapter extends SimpleRecAdapter<HealthResults.ResultBean, HealthRegimenAdapter.ViewHolder>
{

    public static final int TAG_VIEW = 0;

    public HealthRegimenAdapter(Context context)
    {
        super(context);
    }
    
    @Override
    public ViewHolder newViewHolder(View itemView)
    {
        return new ViewHolder(itemView);
    }
    
    @Override
    public int getLayoutId()
    {
        return R.layout.layout_item_food;
    }
    
    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position)
    {
        final HealthResults.ResultBean item = data.get(position);
        holder.tvTitle.setText(item.getTitle());
        holder.tvCount.setText(item.getCount() + "人看过");
        holder.tvKeyword.setText(item.getKeywords());
        ILFactory.getLoader().loadNet(holder.ivCover, item.getImg(), null);

        holder.itemView.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                if (getRecItemClick() != null)
                {
                    getRecItemClick().onItemClick(position, item, TAG_VIEW, holder);
                }
            }
        });
    }
    
    public static class ViewHolder extends RecyclerView.ViewHolder
    {
        
        @BindView(R.id.iv_Cover)
        TintImageView ivCover;
        
        @BindView(R.id.tv_title)
        TintTextView tvTitle;
        
        @BindView(R.id.tv_count)
        TintTextView tvCount;
        
        @BindView(R.id.tv_keyword)
        TintTextView tvKeyword;
        
        public ViewHolder(View itemView)
        {
            super(itemView);
            KnifeKit.bind(this, itemView);
            AutoUtils.autoSize(itemView);
        }
    }
    
}
